﻿using System;
using System.Collections.Generic;
using System.Linq; 
using NTTDATA.BEENChina.ResultCertification.Config;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0202", Name = "年号检证_西历年号空", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0202:VerfityOneResult
    {


        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
   
           


            List<string> entryResults = result.Select(t => (t == null || t.Count == 0) ? string.Empty : t[0]).ToList();

            //for debug
            foreach (var entryResult in entryResults)
            {
                System.Console.WriteLine(string.Format("formid:{0} result:{1}", ChildImageObject.FormId, entryResult));  

                //得到年号位置
                List<string>   arrayDateFormat = ChildImageObject.CategorySetting.DataFormat.Split(new char[] {'/'}).ToList();

                int indexGannNenn = arrayDateFormat.IndexOf("gg");
                int indexYear = arrayDateFormat.IndexOf("yy");

                if (indexYear == -1)
                    indexYear = arrayDateFormat.IndexOf("yyyyy");


                if (indexGannNenn > -1)
                {
                    //拆分结果
                    List<string> entry = entryResult.Split(new char[] { '/' }).ToList();

                    string year = entry[indexYear];
                    string gannNenn = entry[indexGannNenn];

                    if (String.IsNullOrEmpty(gannNenn) && year.Length == 4)
                    {
                        bresult = true;
                    }
                    else
                    {
                        bresult = false;
                    }
                }
                
                if (bresult)
                    break;
            }
  

            if (bresult)
            {
                System.Console.WriteLine("VerfityRq0202");
            }

            return bresult;   
        }
         

        

    }
}